package com.ssm.controller;

import com.ssm.entity.User;
import com.ssm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/user")
    public String showAdd(){
        return "useradd";
    }

    @RequestMapping("/adduser")
    public String addUser(User user){
        userService.addUser(user);
        return "redirect:/listuser";
    }

    @RequestMapping("/updateuser")
    public String updateUser(User user){
        userService.updateUser(user);
        return "redirect:/listuser";
    }
    @RequestMapping("/deluser")
    public String delUser(int id){
        userService.delUser(id);
        return "redirect:/listuser";
    }
    @RequestMapping("/listuser")
    public String ListUser(Model model){
        model.addAttribute("list",userService.queryAllUser());
        return "userlist";
    }
    @RequestMapping("/getuser")
    public String getUser(int id,Model model){
        model.addAttribute("user",userService.getUserById(id));
        return "useredit";
    }

}
